﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Mail;
using Esav.ExceptionManagement;

namespace RelateImageDocALS
{
    public class SendMail
    {
        public void EnviarMail(String toAddress, String fromAddres, String subject, String body, String serverSMTP, String user, String password)
        {

            MailMessage msg = new MailMessage();
            String[] fromAddressArray;
            char[] delimit = new char[] { ';' };
            fromAddressArray = toAddress.Split(delimit);
            foreach (String address in fromAddressArray)
            {
                msg.To.Add(new MailAddress(address));
            }
            msg.From = new MailAddress(fromAddres);
            msg.Subject = subject;
            msg.Body = body;
            msg.IsBodyHtml = true;
            SmtpClient clienteSmtp = new SmtpClient(serverSMTP);

            clienteSmtp.Credentials = new NetworkCredential(user, password);
            try
            {
                clienteSmtp.Send(msg);
            }
            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
                throw ex;
            }
        }
    }
}
